local jiduan = fk.CreateSkill{
    name = "XD__jiduan",
}
Fk:loadTranslationTable{
    ["XD__jiduan"] = "机断",
    [":XD__jiduan"] = "回合开始时，你可令本回合以下一项-1，另外两项+1；若你以此法令摸牌阶段摸牌数-1，你获得技能<a href = ':XD__xuanhuo'><font color='#ff9244'>“眩惑”</font></a>。"..
    "<br>1.摸牌阶段摸牌数，2.出牌阶段使用【杀】的次数，3.手牌上限。",
    ["#XD__jiduan1"] = "额定摸牌数",
    ["#XD__jiduan2"] = "使用【杀】的次数（%arg）",
    ["#XD__jiduan3"] = "手牌上限（%arg）",
    ["@XD__jiduan1-turn"] = "额定摸牌数",
    ["@XD__jiduan2-turn"] = "出杀次数",
    ["@XD__jiduan3-turn"] = "手牌上限",
    ["#XD__jiduan"] = "机断：你可令本回合以下一项-1，另外两项+1",
}

jiduan:addEffect(fk.TurnStart, {
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(jiduan.name)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local card = Fk:cloneCard("slash")
        local card_skill = card.skill
        local all_choices = {
            "#XD__jiduan1",
            "#XD__jiduan2:::"..card_skill:getMaxUseTime(player, Player.HistoryPhase, card, nil),
            "#XD__jiduan3:::"..player:getMaxCards(),
            "Cancel"
        }
        local choices = table.simpleClone(all_choices)
        if card_skill:getMaxUseTime(player, Player.HistoryPhase, card, nil) < 1 then
            table.removeOne(choices, all_choices[2])
        end
        if player:getMaxCards() < 1 then
            table.removeOne(choices, all_choices[3])
        end
        local choice = room:askToChoice(player, {
            choices = choices,
            all_choices = all_choices,
            skill_name = jiduan.name,
            prompt = "#XD__jiduan",
        })
        if choice ~= "Cancel" then
            event:setCostData(self, choice)
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local choice = event:getCostData(self)
        p(choice)
        for i = 1, 3, 1 do
            p(choice:startsWith("#XD__jiduan"..i))
            if choice:startsWith("#XD__jiduan"..i) then
                room:setPlayerMark(player, "@XD__jiduan"..i.."-turn", "-1")
                room:setPlayerMark(player, "XD__jiduan"..i.."-turn", -1)
                if i == 1 then
                    room:handleAddLoseSkills(player, "XD__xuanhuo")
                end
            else
                room:setPlayerMark(player, "@XD__jiduan"..i.."-turn", "+1")
                room:setPlayerMark(player, "XD__jiduan"..i.."-turn", 1)
            end
            p(player:getMark("XD__jiduan"..i.."-turn"))
        end
    end,
})

jiduan:addEffect(fk.DrawNCards, {
    can_refresh = function (self, event, target, player, data)
        return target == player and player:getMark("XD__jiduan1-turn") ~= 0
    end,
    on_refresh = function (self, event, target, player, data)
        data.n = data.n + player:getMark("XD__jiduan1-turn")
    end,
})

jiduan:addEffect("targetmod", {
    residue_func = function (self, player, skill, scope, card, to)
        if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
            return player:getMark("XD__jiduan2-turn")
        end
    end,
})

jiduan:addEffect("maxcards",{
    correct_func = function (self, player)
        return player:getMark("XD__jiduan3-turn")
    end,
})

return jiduan